package com.nisco.dms.util.auto;

import java.util.ArrayList;
import java.util.List;

import com.nisco.dms.entity.SqlColumn;
import com.nisco.dms.entity.SqlTable;

/**
 * controller文件自动生成
 * 
 * @author Robin. 2013-1-24
 * 
 */
public class ControllerAuto {
	private String keyStr;
	private SqlTable sqlTable;

	public ControllerAuto(SqlTable sqlTable, List<SqlColumn> columns) {
		this.sqlTable = sqlTable;
	}
	/**
	 * 生成controller文件
	 */
	public void createController() {
		List<String> list = new ArrayList<String>();
		// 获取模板
		TextFile textFile = new TextFile(
				"src/main/resources/codeTemplate/ControllerTemplate.txt");

		keyStr = WordUtil.firstUpper(WordUtil.spliteWord("_",
				sqlTable.getTabName()));
		list.add("[name]" + "<==>" + keyStr);
		list.add("[name_s]" + "<==>"
				+ WordUtil.spliteWord("_", sqlTable.getTabName()));
		textFile.write(
				"src/main/resources/autocode/" + keyStr + "Controller.java", list);
	}
}
